package com.itheima.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.MemberDao;
import com.itheima.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import pojo.Member;

import java.util.ArrayList;
import java.util.List;

@Service(interfaceClass = MemberService.class)
public class MemberServiceImpl implements MemberService {
    @Autowired
    private MemberDao memberDao;
    
    /**
     * 根据电话查询会员
     */
    @Override
    public Member findMemberByPhoneNumber(String phoneNumber) {
        return memberDao.findMemberByPhoneNumber(phoneNumber);
    }
    
    /**
     * 添加会员
     * @param member
     */
    @Override
    public void add(Member member) {
        memberDao.add(member);
    }
    
    /**
     * 根据月份列表查询会员数量
     */
    @Override
    public List<Integer> findMemberCountsListByRegTimes(List<String> months) {
        //数据库中RegTime格式为：2022-09-12
        //month的格式为：2022-09
        List<Integer> memberCounts = new ArrayList<>();
        if(months != null && months.size() > 0){
            
            for (String month : months) {
                month = month + ".31";
                Integer memberCount = memberDao.findMemberCountByRegTime(month);
                memberCounts.add(memberCount);
            }
        }
        return memberCounts;
    }
    
}
